/*
This file was created on 12/5/2019 and provides the Stata 
code to reproduce the results in the tables and figures for:
"The Cultural Realignment of State White Electorates in the 21st Century"
*/


clear
use replication_data.dta


*	As described in the text, all variables, except presidential vote, are
*	scaled the 10th percentile value (the fifth out of the 50 states) is coded
*	0 and the 90th percentile (the 45th out of the 50 states) is coded 1.

* Rescaling Variables *
sum	///
	pid2000 pid2004 pid2008 pid2012 pid2016  ///
	cult2000 cult2004 cult2008 cult2012 cult2016  ///
	econ2000 racial2000 ///
	black2000 hispanic2000 pbachelors adjinc_cap urban2000 p_evang conger2000 forborn2000
	
foreach v of varlist 	///	
	pid2000 pid2004 pid2008 pid2012 pid2016  ///
	cult2000 cult2004 cult2008 cult2012 cult2016  ///
	econ2000 racial2000 ///
	black2000 hispanic2000 pbachelors adjinc_cap urban2000 p_evang conger2000 forborn2000 {
		sort `v'
		local a=`v'[5]
		local b=`v'[45]
		local c=`b'-`a'
		replace `v'=round((`v'-`a')/(`c'),.001)
	}
sum	///
	pid2000 pid2004 pid2008 pid2012 pid2016  ///
	cult2000 cult2004 cult2008 cult2012 cult2016  ///
	econ2000 racial2000 ///
	black2000 hispanic2000 pbachelors adjinc_cap urban2000 p_evang conger2000 forborn2000

	
	

*******************************
***** RESULTS REPLICATION *****
*******************************


*** Table 1 -- Panel A ***
regress cult2004 cult2000 pid2000 
regress cult2008 cult2004 pid2004 
regress cult2012 cult2008 pid2008 
regress cult2016 cult2012 pid2012 


*** Table 1 -- Panel B ***
regress pid2004 cult2000 pid2000 
regress pid2008 cult2004 pid2004 
regress pid2012 cult2008 pid2008 
regress pid2016 cult2012 pid2012 

*** Table 2 -- column 1 ***
regress pid2016  cult2000 pid2000


*** Table 2 -- column 2 ***
regress cult2016 cult2000 pid2000


*** Figure 1 -- column 1 ***
regress cult2016 cult2000 pid2000

avplot cult2000 	///
	, msymbol(none) mlabel(abbrev) mlabsize(vsmall) mlabcolor(black) mlabposition(0) 	///
	rlopts(lcolor(black) lwidth(thin)) ytitle(Cultural Issues 2016) ytitle(, margin(small)) 	///
	ylabel(-.6(.3).9, angle(horizontal) nogrid) xtitle(Cultural issues 2000) xtitle(, margin(small)) /// 
	xlabel(-.9(.3).9) legend(off) graphregion(fcolor(white) lcolor(black))

avplot pid2000	///
	, msymbol(none) mlabel(abbrev) mlabsize(vsmall) mlabcolor(black) mlabposition(0) 	///
	rlopts(lcolor(black) lwidth(thin)) ytitle(Cultural Issues 2016) ytitle(, margin(small)) ///
	ylabel(-.6(.3).9, angle(horizontal) nogrid) xtitle(Partisanship 2000) xtitle(, margin(small)) ///
	xlabel(-.9(.3).9) legend(off) graphregion(fcolor(white) lcolor(black))

	
*** Figure 1 -- column 2 ***
regress pid2016 cult2000 pid2000 ,beta

avplot cult2000	///
	, msymbol(none) mlabel(abbrev) mlabsize(vsmall) mlabcolor(black) mlabposition(0) ///
	rlopts(lcolor(black) lwidth(thin)) ytitle(Partisanship 2016) ytitle(, margin(small)) ///
	ylabel(-.6(.3).9, angle(horizontal) nogrid) xtitle(Cultural issues 2000) xtitle(, margin(small)) ///
	xlabel(-.9(.3).9) legend(off) graphregion(fcolor(white) lcolor(black))
	
avplot pid2000	///
	, msymbol(none) mlabel(abbrev) mlabsize(vsmall) mlabcolor(black) mlabposition(0) ///
	rlopts(lcolor(black) lwidth(thin)) ytitle(Partisanship 2016) ytitle(, margin(small)) ///
	ylabel(-.6(.3).9, angle(horizontal) nogrid) xtitle(Partisanship 2000) xtitle(, margin(small)) ///
	xlabel(-.9(.3).9) legend(off) graphregion(fcolor(white) lcolor(black))


*** Table 3 ***
foreach y of numlist 2000(4)2016 {
	regress pvote`y' pid2000 cult2000 econ2000 racial2000
}

*** Table 4 ***
regress cult2000 	///
	south black2000 hispanic2000 pbachelors adjinc_cap urban2000 	///
	p_evang conger2000 forborn2000